from pprint import pprint
import os
from docx import Document
path="D:\SVN_Serve_Resource\GWM_SRD"
excel_path = "输入输出信号.xlsx"
def doc_to_docx(path):
    path_list = os.listdir(path)
    #pprint(path_list)
    doc_list = [os.path.join(path,str(i)) for i in path_list if str(i).endswith("docx")]
    pprint(doc_list[10])
    '''
    wb = Workbook(excel_path)
    wb.save(excel_path)
    wb = load_workbook(excel_path)
    wb.create_sheet("TT")
    ws = wb.active
    ''' 
    '''
    word = wc.Dispatch('Word.Application')
    wordlist_path =[]
    word.Visible=0 #后台运行
    word.DisplayAlerts =0 #不显示，不警告
    doc = word.Documents.Open("D:\SVN_Serve_Resource\GWM_SRD\GWM_V3.5_Cluster_SRD_Gauge_AutoLink_V7.3.docx") #打开文档

    data = doc.paragraphs[0].text
    pprint(data)
    print("----------------------")
    print("段落数",doc.Paragraphs.count)
    for i in range(len(doc.Paragraphs)):
        para = doc.Paragraphs[i]
        print(para.Range.text)
    '''
    doc = Document(doc_list[10]) 
    for table in doc.tables:
        for row_index,row in enumerate(table.rows):  
            for col_index, cell in enumerate(row.cells):
                if table.cell(0,0).text == "消息名" and table.cell(0,1).text == "CAN ID":
                    if col_index == 0 and row_index > 0:
                        print("%s "%cell.text,end=" ")
                    if col_index == 1 and row_index > 0:
                        print("%s "%cell.text,end=" ")
                    if col_index == 2 and row_index > 0:
                        print("%s "%cell.text,end=" ")    
                    if col_index == 3 and row_index > 0:
                        print("%s "%cell.text,end=" ") 
                    if col_index == 4 and row_index > 0:
                        print("%s "%cell.text)                 
#end doc_to_docx


doc_to_docx(path)